<template>
  <div class="news-box" :class="{ 'full-statis': fullWindow }">
    <div class="news-tabs-box">
      <je-tabs v-model:activeKey="activeMenuId" @change="handleChangeTab">
        <je-tab-pane v-for="menuItem in menuList" :key="menuItem.id" :tab="menuItem.text">
          <news-list
            :news-code="menuItem.code"
            :full-window="fullWindow"
            :active-menu-id="activeMenuId"
            :file-menu-id="fileMenuId"
          />
        </je-tab-pane>
      </je-tabs>
      <i
        class="news-full-window"
        :class="{ 'fal fa-arrows-maximize': !fullWindow, 'fal fa-arrows-minimize': fullWindow }"
        @click="handleWindow"
      ></i>
    </div>
  </div>
</template>

<script>
  import { defineComponent, reactive, toRefs, onMounted, ref } from 'vue';
  import NewsList from '@/views/board-home/components/news-list.vue';
  import { Tabs } from 'ant-design-vue';
  import { GetNewsMenu } from '@/api';

  export default defineComponent({
    name: 'NewsMain',
    components: {
      JeTabs: Tabs,
      JeTabPane: Tabs.TabPane,
      NewsList,
    },
    setup() {
      let fullWindow = ref(false); //是否放大屏幕操作
      const state = reactive({
        menuList: [], //公告菜单
        activeMenuId: '', //当前公告菜单id
        fileMenuId: '', //文件按钮id
      });
      const methods = {
        handleWindow() {
          //窗口放大/还原
          fullWindow.value = !fullWindow.value;
        },
        getAllMenu() {
          //获取公告菜单
          const param = {
            DICTIONARY_DDCODE: 'JE_SYS_NOTICETYPE',
          };
          GetNewsMenu(param).then((res) => {
            if (res.length > 0) {
              res.forEach((item) => {
                if (item.text == '附件') {
                  state.fileMenuId = item.id;
                }
              });
              state.menuList = res;
              state.activeMenuId = res[0].id;
            }
          });
        },
        handleChangeTab(activeKey) {
          //切换tab
          state.activeMenuId = activeKey;
        },
      };
      onMounted(() => {
        methods.getAllMenu();
      });
      return {
        fullWindow,
        ...toRefs(state),
        ...methods,
      };
    },
  });
</script>
<style>
  .news-tabs-box .ant-tabs-nav-wrap {
    height: 60px;
    border-bottom: 1px solid #ecedf0;
  }
  .news-tabs-box .ant-tabs-tab-btn {
    transition: none;
  }
  .news-tabs-box .ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn {
    font-size: 18px;
    color: #3f3f3f;
    font-weight: bold;
    padding: 0;
  }
  .news-tabs-box .ant-tabs-tab.ant-tabs-tab-active {
    padding: 0px;
  }
  .news-tabs-box .ant-tabs > .ant-tabs-nav .ant-tabs-nav-wrap,
  .news-tabs-box .ant-tabs > div > .ant-tabs-nav .ant-tabs-nav-wrap {
    align-items: center;
  }
  .news-tabs-box .ant-tabs > .ant-tabs-nav .ant-tabs-nav-list,
  .news-tabs-box .ant-tabs > div > .ant-tabs-nav .ant-tabs-nav-list {
    height: 30px;
  }
  .news-tabs-box .ant-tabs-tab + .ant-tabs-tab {
    margin: 0 0 0 30px;
  }
  .news-tabs-box .ant-tabs-top > .ant-tabs-nav,
  .news-tabs-box .ant-tabs-bottom > .ant-tabs-nav,
  .news-tabs-box .ant-tabs-top > div > .ant-tabs-nav,
  .news-tabs-box .ant-tabs-bottom > div > .ant-tabs-nav {
    margin: 0;
  }
  .news-tabs-box .ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn {
    text-shadow: none;
  }
</style>
<style scoped lang="less">
  .news-tabs-box {
    width: 100%;
    border-radius: 4px;
    background-color: #ffffff;
    padding: 0 20px;
    position: relative;
    .news-full-window {
      position: absolute;
      cursor: pointer;
      top: 22px;
      right: 20px;
      color: #8d98ab;
      font-size: 14px;
    }
  }
  .news-box {
    width: 100%;
    border-radius: 4px;
    background-color: #ffffff;
    margin-top: 20px;
    .news-header {
      width: 100%;
      height: 60px;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #f5f5f5;
      .news-left {
        display: inline-flex;
        align-items: center;
        .news-item {
          margin-right: 30px;
          font-size: 14px;
          color: #3f3f3f;
          cursor: pointer;
        }
        .news-item-select {
          font-size: 18px;
          font-weight: bold;
          border-bottom: 2px solid #3265f5;
        }
      }
      .news-right {
        cursor: pointer;
        i {
          font-size: 14px;
          color: #adadad;
        }
      }
    }
  }
  .full-statis {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 0px;
    z-index: 100;
    margin-top: 0;
  }
</style>
